using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace OA.BLL
{
    public class EventsNotify:Base
    {
        private DAL.EventsNotify dal = null;

        public EventsNotify()
        {
            isession = DB_help.NHibernateHelper.GetCurrentSession(DefaultDataBase);
            dal=new DAL.EventsNotify(isession);
        }

        public Common.Result Add(string EventCode,string UserName)
        {
            Common.Result ret = new Common.Result(false, 0, "添加失败");
            var Events = new DAL.Events(isession).GetModel(EventCode);
            if (Events == null)
            {
                ret.message = "事件编号不存在";
                return ret;
            }
            var tran = isession.BeginTransaction();
            foreach (var u in UserName.Split(','))
            {
                if (dal.Get(EventCode, u) == null && new DAL.Manager(isession).GetModel(u)!=null)
                {
                    var value = new Model.EventsNotify()
                    {
                         EventCode=EventCode,
                         UserName=u
                    };
                    ret = dal.Add(value);
                }
            }
            tran.Commit();

            return ret;
        }

        public Common.Result Delete(string Eventcode,string ids)
        {
            var ret = dal.Delete(Eventcode, ids);
            return ret;
        }

        public Model.EventsNotify Get(int id)
        {
            return dal.GetModel(id);
        }

        public IList<Model.EventsNotify> Get(string where, string orderby, int start, int length, params object[] ps)
        {
            return dal.Get(where, orderby, start, length, ps);
        }

        public int GetCount(string where, params object[] ps)
        {
            return dal.GetCount(where, ps);
        }
    }
}
